$NG.AllReady(function (page, { useDataIndexChange, useUpdateRow,useValuesChange , useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_telephone_plan_m")
    const grid = $NG.getCmpApi("p_form_telephone_plan_d")
    let cityMap = {}
    $NG.execServer("getQweQwe", {}, function(res){
        console.log(res);
        console.log('测试', JSON.parse(res.data)[0]);
    })
    $NG.updateUI(updater => {
        console.log(updater.editGrid.p_form_telephone_plan_d.u_telephine);
        updater.editGrid.p_form_telephone_plan_d.u_telephine.setProps((p)=>{
            return {
                ...p, editor: {
                  ...p.editor,
                  onDoubleClick(){
                    console.log('双击成功!!!!!');
                  }
                }
            }
        })
    })

    //监听事业部
    useValuesChange(({args})=>{
        console.log(`事业部监听`, args[0]);
        getGxrInfo()
        getAllGxr()
        proDFilter()

    },"p_form_telephone_plan_m.cur_orgid")

    useUpdateRows(({args})=>{
        console.log(`监听表格行为`);
        const row = args[0]
        let lock = false
        row.forEach(item => {
            if(item.u_visit_way !== '电话回访'){
                item.u_visit_way = "电话回访"
                lock = true
            }
        })
        if(lock){
            grid.refreshView()

        }
    }, "p_form_telephone_plan_d")
    // 获取干系人信息
    function getGxrInfo(){
        grid.clearRows()
        grid.refreshView()
        $NG.execServer("getAllFilterGxr", {phid_org:mstform.getItem("cur_orgid").getValue()},function(res){
            console.log(`获取干系人响应式数据`, res);
            console.log(`检查缓存`, cityMap);
            if(res.count == 0 ) return
            const datas = JSON.parse(res.data)
            console.log(datas);
            const _arr = []
            datas.forEach(item => {
                const _data = item.extendObjects
                _arr.push({
                    phid_pc:{
                        label:_data.bill_name,
                        value:_data.phid_pc
                    },
                    u_provice:{
                        label:cityMap[_data.pno]||"",
                        value:_data.pno||""
                    },
                    u_city:{
                        label:cityMap[_data.cno]||"",
                        value:_data.cno||""
                    },
                    u_khdwmc:_data.khdwmc,
                    u_gxr:{
                        label:_data.u_gxr_xm,
                        value:_data.u_gxr
                    },
                    u_gxrzt:_data.u_gxrzt,
                    u_telephine:_data.u_mobile_phone,
                    u_s_visit_time:_data.u_visit_time,
                    u_schfqk:_data.schfqk,
                    u_remarks:_data.u_remarks
                })
            })
            grid.addRows(_arr)
            grid.refreshView()
        })
    }
    // 获取省份信息
    function getAllGxr(){
        $NG.execServer("getAllCity", {}, function(res){
            getGxrInfo()
            const _data = JSON.parse(res.data)
            const _map = {}
            _data.forEach(item =>{
                const datas = item.extendObjects
                _map[datas.pid] = datas.pname
                _map[datas.cno] = datas.cname
            })
            cityMap = {..._map}
        })
    }
    function proDFilter(){
        const phid_pcc = $NG.getCmpApi('p_form_telephone_plan_m').getItem('cur_orgid').getValue();
        if(!phid_pcc){
          return 
        }
        $NG.updateUI(updater => updater.editGrid.p_form_telephone_plan_d.phid_pc.setProps((p) => {
          return {
            ...p, editor: {
              ...p.editor,
              clientSqlFilter: { phid_org: $NG.getCmpApi('p_form_telephone_plan_m').getItem('cur_orgid').getValue() },
            }
          };
        }));
    }
});

